a = []
for i in range(3):
    a.append(input())
b = ""
q = 0
for e in a:
    if e == "one":
        b += "1"
    elif e == "two":
        b += "2"
    elif e == "three":
        b += "3"
    elif e == "four":
        b += "4"
    elif e == "five":
        b += "5"
    elif e == "six":
        b += "6"
    elif e == "seven":
        b += "7"
    elif e == "eight":
        b += "8"
    elif e == "nine":
        b += "9"
    elif e == "zero":
        b += "0"
    else:
        print("Wrong input")
        q = 1
        break
if q == 0:
    c = int(b)
    t = c + 1
    d = []
    h = []
    for i in range(2, c):
        for j in range(2, i):
            if i % j == 0:
                d.append(j)
        if len(d) > 0:
            d = []
            continue
        else:
            h.append(i)
            continue
    k = []
    n = []
    while len(n) == 0:
        for j in range(2, t):
            if t % j == 0:
                k.append(j)
        if len(k) > 0:
            k = []
            t += 1
            continue
        else:
            n.append(t)
            break
    if c - h[-1] > n[0] - c:
        print(n[0])
    else:
        print(h[-1])